package com.sh1604.duitang.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.sh1604.duitang.R;
import com.sh1604.duitang.constant.UrlString;
import com.sh1604.duitang.mybean.ImageBean;
import com.sh1604.duitang.utils.OKHttpUtils;
import com.squareup.picasso.Picasso;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class HotPhotoActivity extends AppCompatActivity {

    @InjectView(R.id.hor_scro)
    HorizontalScrollView horScro;
//    @InjectView(R.id.hor_recy)
//    RecyclerView horRecy;
    private List<ImageBean.DataBean.GroupItemsBean> mList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hot_photo);
        ButterKnife.inject(this);
        mList = new ArrayList<>();

        OKHttpUtils.newInstance(this).getAsyncMainData(UrlString.URL_FIND, new OKHttpUtils.MyCallBack() {
            @Override
            public void onFailure(IOException e) {

            }

            @Override
            public void onResponse(String result) {
                ImageBean bean = new Gson().fromJson(result,ImageBean.class);
                mList.addAll(bean.getData().get(0).getGroup_items());
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        initData();
                    }
                });
            }
        });

    }

    private void initData() {
        final LinearLayout layout2 = new LinearLayout(this);
        layout2.setOrientation(LinearLayout.HORIZONTAL);
        Log.i("wo","090909009090090--------"+mList.size());
        for (int i = 0; i < mList.size(); i++) {
            TextView tv = new TextView(this);
            ImageView iv = new ImageView(this);
            iv.setLayoutParams(new ViewGroup.LayoutParams(100,100));
            Picasso.with(this).load(mList.get(i).getIcon_url()).into(iv);
            Log.i("wo1","090909009090090--------"+mList.get(i).getIcon_url());
            tv.setText(mList.get(i).getName());
            layout2.addView(iv);
            layout2.addView(tv);
        }
        horScro.addView(layout2);
    }
}
